package com.hmall.item.web;

import com.hmall.category.pojo.Category;
import com.hmall.common.PageBean;
import com.hmall.item.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("item/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    //增加一条记录
    @PostMapping
    public void add(@RequestBody Category category) {
        categoryService.add(category);
    }
    //根据id删除一条记录
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        categoryService.delete(id);
    }
    //修改一条记录
    @PutMapping
    public void update(@RequestBody Category category) {
        categoryService.update(category);
    }
    //分页查询
    @GetMapping("list")
    public PageBean list(Integer page, Integer size) {
        PageBean<Category> pageBean = categoryService.list(page, size);
        return pageBean;
    }
}
